package com.origin.multimedia.music;


import android.util.Log;

import com.origin.multimedia.music.bean.MusicInfo;

import java.util.ArrayList;
import java.util.List;

public class MusicPlayList {
    // 移动的下标
    volatile static int point;
    // 正在播放
    volatile static int mCurrentPoint;
    static List<MusicInfo> musicInfoList = new ArrayList<>();

    public static void addAll(List<MusicInfo> list) {
        musicInfoList.clear();
        musicInfoList.addAll(list);
    }

    public static synchronized MusicInfo next() {
        return play();
    }
    public static synchronized int previousPoint() {
        point = --mCurrentPoint;
        if (point > musicInfoList.size()) {
            mCurrentPoint = point = 0;
        } else if (point < 0) {
            mCurrentPoint = point = musicInfoList.size() - 1;
        }
        return mCurrentPoint;
    }
    public static synchronized int nextPoint() {

        if (point > musicInfoList.size()-1) {
            point = 0;
        } else if (point < 0) {
            point = musicInfoList.size() - 1;
        }
        mCurrentPoint = point;
        point++;
        return mCurrentPoint;
    }

    public static synchronized MusicInfo previous() {
        point = --mCurrentPoint;
        if (point > musicInfoList.size()) {
            mCurrentPoint = point = 0;
        } else if (point < 0) {
            mCurrentPoint = point = musicInfoList.size() - 1;
        }
        return musicInfoList.get(point);
    }

    public static synchronized MusicInfo play() {
        if (point > musicInfoList.size()-1) {
            point = 0;
        } else if (point < 0) {
            point = musicInfoList.size() - 1;
        }
        Log.e("MusicPlayListYang",point+"  point  "+musicInfoList.size());
        MusicInfo musicInfo = musicInfoList.get(point);
        mCurrentPoint = point;
        point++;

        return musicInfo;
    }

    public static synchronized MusicInfo play(int _point) {
        mCurrentPoint = point = _point;
        return play();
    }

    public static synchronized int getCurrentPoint() {
        return mCurrentPoint;
    }

    public static synchronized MusicInfo getCurrentPlay() {
       Log.e("更新","mCurrentPoint  "+mCurrentPoint);
       return play(mCurrentPoint);
    }
}
